const router = require("koa-router")();
const Mock = require("mockjs");
const { list, list1 } = Mock.mock({
  "list|50": [
    {
      image: "@image(150x120, @color)",
      id: "@id",
      title: "@ctitle",
      desc: "@cword(10, 20)",
      "price|1-5": 1,
      "zhekou|1-99": 1,
      "sell|10-10000": 1,
    },
  ],
  "list1|5": [
    {
      title: "ctitle",
      id: "@id",
      "price|-100-1000": 1,
      datetime: "@datetime",
      tip: "@cword(5, 10)",
    },
  ],
});

router.get("/list", (ctx) => {
  const { pageCode = 1, pageSize = 10 } = ctx.request.query;

  ctx.body = {
    code: 200,
    data: list.slice((pageCode - 1) * pageSize, pageCode * pageSize),
  };
});
router.get("/list1", (ctx) => (ctx.body = { code: 200, data: list1 }));

module.exports = router;
